import React from 'react';
import {Button, Menu} from 'antd-mobile';
import {ToolHistory, ToolRoute} from '../utils';
import {configLayout} from '../router/Config';

/**
 * 目录页面：包含工程的所有页面
 */
export default class Home extends React.Component {
  constructor(props) {
    super(props);
    // this.init();
    this.defaultKeys = ['/home', '/home/list']; //菜单的默认key数组
  }

  /**
   * 展示菜单
   */
  render() {
    return (
      <Button onClick={this.toJump.bind(this)}>跳转</Button>
    )
    // return <Menu data={this.menu} value={this.defaultKeys} onChange={this.onChange} />;
  }
  toJump() {
    this.props.history.push({
      pathname: '/order',
      state: {
        hello: 123456
      },
      params: {
        hhh: 55555
      }
    })
  }
  /**
   * 初始化数据
   */
  init() {
    let list = ToolRoute.formatRouter().routerFormat; //菜单列表
    this.menu = [];
    Object.keys(list).forEach((key) => {
      let item = list[key];
      let {path, label} = configLayout[key];
      let data1 = {label, value: path, children: []};
      this.menu.push(data1);

      Object.keys(item).forEach((key2) => {
        let item2 = item[key2];
        if (!item2.view) return;

        data1.children.push({label: item2.label, value: item2.path});
      });
    });
  }

  /**
   * 菜单改变事件
   * @param arr 选中的值
   */
  onChange = (arr) => {
    let path = arr[1];
    ToolHistory.href(path);
  };
}
